package com.opages.netty.demo.netty.stickybag;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author daizhong.liu
 * @create 2021-12-15 14:53
 **/
public class MessageDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        MessageProtocol protocol = new MessageProtocol();
        int len = in.readInt();
        protocol.setLen(len);
        byte[] bytes = new byte[len];
        in.readBytes(bytes);
        protocol.setContent(bytes);
        out.add(protocol);
    }
}
